package com.hy.hello;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import static com.hy.hello.HelloReceiver2.cc;

/**
 * 生产者
 * @author king
 *
 */
@Component
public class HelloSender1 {

	Logger logger = LoggerFactory.getLogger(HelloReceiver2.class);

	public static int cc = 0;

	@Autowired
	private AmqpTemplate rabbitTemplate;

	public int send() {
		String sendMsg = "hello1 " + new Date();
//        System.out.println("Sender1 : " + sendMsg);
        //this.rabbitTemplate.convertAndSend("helloQueue", sendMsg);
		logger.info("HelloSender1>>>>>{}", ++cc);
        int count = (int)this.rabbitTemplate.convertSendAndReceive("helloQueue", sendMsg);
        return count;
	}

}
